<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 静态属性方法

    // 综合案例
    //1、匹配 16 进制颜色值
    //表示一个 16 进制字符，可以用字符组 [0-9a-fA-F]。
    //其中字符可以出现 3 或 6 次，需要是用量词和分支结构（分组）
    //使用分支结构时，需要注意顺序
    var pattern = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/g;
    var color = "#000000";
    console.log(pattern.test(color));

    // 2、匹配时间
    //23:59  02:07   2:7
    // var pattern = /^([01][0-9]|2[0-3]):[0-5][0-9]$/ 
    var pattern = /^(0?[0-9]|1[0-9]|2[0-3]):(0?[0-9]|[1-5][0-9])$/; //改进
    // var pattern = /^(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9])$/;//没有?就必须有0
    // console.log(pattern.test("2:7")); //f
    var time = "02:07";
    console.log(pattern.test((time))); //t
    console.log(pattern.test("2:7")); //t

    // 3、
    var pattern = /(?!^)(?=(\d{3})+$)/g;
    var str = "12345678";
    var stt = str.replace(pattern, ",");
    console.log(str);
    console.log(stt); //12,345,678
    
    var pattern = /(?=(\d{3})+$)/g;
    // var pattern = /(?!^)(?=(\d{3})+$)/g;  //123,456,789
    var str = "123456789";
    var stt = str.replace(pattern, ",");
    console.log(str);
    console.log(stt); //,123,456,789

</script>
</html>